<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<title><spring:message code="message.list.ShangPinMuLuChaKan"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>药品列表</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#">交易</a></li>
            <li class="active"><a href="#">药品列表</a></li>
        </ol>
    </section>
    <section class ="content">
        <form id="form" method="post" class="form-horizontal">    
         <div class=" box box-success">
            <div class="box-body">
               <div class="input">
                    <div class="textalign1"><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="drugName" name="drugName" placeholder="<spring:message code="message.listForm.tongYongMing"/>/<spring:message code="message.listForm.pinYinMa"/>" />
                    </div>
                    
                    <%--<div class="textalign"><spring:message code="message.listForm.yaoPinBianMa"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="drugCode" name="drugCode" placeholder="<spring:message code="message.listForm.yaoPinBianMa"/>" />
                    </div>--%>
                    
                     <div class="textalign1"><spring:message code="message.listForm.ShengChanQiYe"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="compName" name="compName" placeholder="<spring:message code="message.listForm.ShengChanQiYe"/>/<spring:message code="message.listForm.pinYinMa"/>" />
                    </div>
                   <div class="textalign1">药品来源<spring:message code="message.yanZheng.maoHao"/></div>
                        <div class="boxinput">
                        <select class="textinput"  id="goodsSource" name="goodsSource">
                        <option value=""><spring:message code="message.select.option"/></option>
                        <c:forEach items="${list }" var="list">
                            <option value="${list.dicCode }">${list.dicName }</option>
                        </c:forEach>
                        </select>
                    </div>
                    <div class="textalign1" >
	                       <button type="button" onclick="gridSerch()" class="btn btn-success btn-sm" id="selectDicCompType"><spring:message code="message.button.seachSpacing"/></button>
                    </div> 
               </div>
               <div class="moreSerch" style="display:none;">
	               <div class="input">
	                    <div class="textalign1"><spring:message code="message.listForm.ZhongBiaoQiYe"/><spring:message code="message.yanZheng.maoHao"/></div>
	                    <div class="boxinput">
	                        <input type="text" class="textinput" id="catCompName" name="catCompName" placeholder="<spring:message code="message.listForm.ZhongBiaoQiYe"/>" />
	                    </div>
	                    
	                     <div class="textalign"><spring:message code="message.listForm.LianJiaYao"/><spring:message code="message.yanZheng.maoHao"/></div>
	                    <div class="boxinput">
	                        <select class="textinput" id="isSmallprice" name="isSmallprice">
	                            <option value=""><spring:message code="message.select.option"/></option>
	                            <option value="0"><spring:message code="message.listForm.fou"/></option>
	                            <option value="1"><spring:message code="message.listForm.shi"/></option>
	                            <option value="9"><spring:message code="message.listForm.WeiZhi"/></option>
	                        </select>
	                    </div>
	                    <div class="textalign"><spring:message code="message.listForm.GongYingJinZYao"/><spring:message code="message.yanZheng.maoHao"/></div>
	                    <div class="boxinput">
	                        <select class="textinput" id="isSmallsource" name="isSmallsource">
	                            <option value=""><spring:message code="message.select.option"/></option>
	                            <option value="0"><spring:message code="message.listForm.fou"/></option>
	                            <option value="1"><spring:message code="message.listForm.shi"/></option>
	                            <option value="9"><spring:message code="message.listForm.WeiZhi"/></option>
	                        </select>
	                    </div> 	                    
	               </div>
	            </div>  
	            <div class="input" style="display:none;">  
	                   <div class="textalign1" >
	                       <button type="button" onclick="gridSerch()" class="btn btn-success btn-sm" id="selectDicCompType"><spring:message code="message.button.seachSpacing"/></button>
                        </div> 
	            </div>
               
            </div>
           </div>
        </form> 
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
  //绑定回车
    $('#drugName,#projName,#compName,#goodsCode,#drugCode,#catCompName,#isLowprice,#isSmallprice,#isSmallsource,#goodsSource').bind('keydown', function(event) {
        if (event.keyCode == "13") {
            $('#selectDicCompType').click();
        }
    });	
    $("#drugName").focus();//加载页面光标在第一个查询框内
    
    
    
	    var searchType = 0;
	    
	    function moreSerch(obj) {
	        if (searchType == 0) {
	            searchType = 1;
	            $("div.moreSerch").slideDown();
	            $(obj).html("<spring:message code="message.button.JianDanChaXun"/>");
	        } else {
	            searchType = 0;
	            $("div.moreSerch").slideUp();
	            $(obj).html("<spring:message code="message.button.GaoJiChaXun"/>");
	            $("#goodsCode,#drugCode,#catCompName,#isLowprice,#isSmallprice,#isSmallsource").val("");
	        }
	    }
	    
	    function gridSerch(page) {
	        var drugName = $.trim($("#drugName").val());
	        var projName = $.trim($("#projName").val());
	        var compName = $.trim($("#compName").val());
	        var goodsCode = $.trim($("#goodsCode").val());
	        var drugCode = $.trim($("#drugCode").val());
	        var catCompName = $.trim($("#catCompName").val());
	        var isLowprice = $.trim($("#isLowprice").val());
	        var isSmallprice = $.trim($("#isSmallprice").val());
	        var isSmallsource = $.trim($("#isSmallsource").val());
	        var goodsSource = $.trim($("#goodsSource").val());
	        var status = $.trim($("#status").val());
	
	        $("#gridlist").jqGrid('setGridParam', {  
	            datatype:'json',
	            postData:{
	                "drugName":drugName,
	                "projName":projName,
	                "compName":compName,
	                "goodsCode":goodsCode,
	                "drugCode":drugCode,
	                "catCompName":catCompName,
	                "isLowprice":isLowprice,
	                "isSmallprice":isSmallprice,
	                "isSmallsource":isSmallsource,
	                "goodsSource":goodsSource,
	                "status":status
	            },
	            page:1
	        }).trigger("reloadGrid"); //重新载入  
	    }
    
        $(function () {
        	 //商品分类查询
        	 $("#drugCat").HNSelect({
        	    url: "${pageContext.request.contextPath}/selectController/getDicSys.html",
        	    data: { ID: '115' },
        	    defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
        	});
        	 

            $("#gridlist").jqGrid({
                url: "getBaseGoodsListJsonByHosp.html",
                mtype: "POST",
                postData: { "projId" : "${bidProject.projId}"},
                datatype: "json",
                autowidth: true,
				shrinkToFit:false,
                height:350,
                colNames:[
                          '<spring:message code="message.jqGrid.cz"/>',
		   	              '<spring:message code="message.listForm.shangBianMa"/>',
		   	              '<spring:message code="message.listForm.ZhongBiaoJia"/>',
		   	           	  '<spring:message code="message.listForm.ZhongBiaoHouLingShouJia"/>',
		   	              '<spring:message code="message.listForm.tongYongMing"/>', 
                          '<spring:message code="message.listForm.jiXing"/>',
                          '<spring:message code="message.listForm.guiGe"/>',
                          '<spring:message code="message.listForm.zhuanHuanXiShu"/>',
                          '<spring:message code="message.listForm.baoZhuangDanWei"/>', 
                          '<spring:message code="message.listForm.shengChanQiYe"/>',
                          '国药准字',
						  '<spring:message code="message.listForm.yaoPinLaiYuan"/>',
						  '药品类别',
                          '<spring:message code="message.listForm.ZhongBiaoQiYe"/>',
	        	   	      '<spring:message code="message.listForm.XiangMuMingCheng"/>',
                          ],
                colModel:[
                    {name:'oper',index:'oper',hidden:true, width:40, align:"center",sortable:false,
                        formatter : function(val, opts, rowdata) {
                        var str = "";
                         if (rowdata.status == 1){
                        str = "<a href=\"javascript:void(0);\" onclick=\"switchStatus('"+rowdata.goodsCode+"','0');\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -40px 0px' class='opIcon' title='<spring:message code="message.listForm.TingYong"/>'></a>";
                         } else if (rowdata.status == 0){
                         str = "<a href=\"javascript:void(0);\" onclick=\"switchStatus('"+rowdata.goodsCode+"','1');\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -60px 0px' class='opIcon' title='<spring:message code="message.listForm.QiYong"/>'></a>";
                         }
                      return str;
                      } 
                    },
                    {name:'goodsCode',hidden:true,index:'goodsCode', width:100,align:"center", sortable:false,
                    }, 
	                {name:'proPriceLimit',index:'proPriceLimit', width:90, align:"right",sortable:false,
	                    formatter:function(cellvalue, options, row) {
	                        var f_x = Math.round(cellvalue * 100) / 100;
	                        var s_x = f_x.toString();
	                        var pos_decimal = s_x.indexOf('.');
	                        
	                        if (pos_decimal < 0) {
	                            pos_decimal = s_x.length;
	                            s_x += '.';
	                        }
	                        
	                        while (s_x.length <= pos_decimal + 2) {
	                            s_x += '0';
	                        }
	                        return s_x;
	                    }
	                },
	                {name:'retailPriceLimit',index:'retailPriceLimit', width:120, align:"right",sortable:false,
	                    formatter:function(cellvalue, options, row) {
	                        var f_x = Math.round(cellvalue * 100) / 100;
	                        var s_x = f_x.toString();
	                        var pos_decimal = s_x.indexOf('.');
	                        
	                        if (pos_decimal < 0) {
	                            pos_decimal = s_x.length;
	                            s_x += '.';
	                        }
	                        
	                        while (s_x.length <= pos_decimal + 2) {
	                            s_x += '0';
	                        }
	                        return s_x;
	                    }
	                },
                    {name:'qualityspecName',index:'drugName', width:200,align:"left", sortable:false},
                    {name:'formName',index:'formName', width:80, align:"center",sortable:false},
                    {name:'specName',index:'specName', width:80, align:"center",sortable:false},
                    {name:'factor',index:'factor', width:80, align:"center",sortable:false},
                    {name:'unitName',index:'unit', width:60, align:"center",sortable:false},
                    {name:'compName',index:'compName', width:180, align:"left",sortable:false},
                    {name:'drugMedicine',index:'drugMedicine', width:140, align:"left",sortable:false},
					{name:'goodsSourceName',index:'goodsSourceName',sortable: false, width:80, align:"left",sorttype:false},
					{name:'drugAttr',index:'drugAttr',sortable: false, width:80, align:"left",sorttype:false,
						formatter : function(val, opts, rowdata) {
							var str = "";
							if (val == 1) {
								str = "国家基本药物";
							} else if (val == 2) {
								str = "非基本药物";
							} else if (val == 3) {
								str = "省增补基本药物";
							} 
							return str;
						}
					},
                    {name:'catCompName',index:'compName', width:200, align:"left",sortable:false},
                    
                    {name:'projName',index:'projectName',hidden:true, width:200, align:"left",sortable:false}
                ],
                rowNum: 20,
                rowList: [10, 20,50,100],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
              //序号宽度自动变化
                gridComplete:function(){
                	//序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                	//数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
                },
                caption: "药品列表",
                jsonReader: {
                    repeatitems: false,
                    //id: "drugId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
			$("#gridlist").jqGrid("setGridHeight",create());
            
        });


        function batchSubmitDrugTOProj(){
        	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];

    		if (rowIds.length <= 0) {
    			$.HN.message.alert("<spring:message code="message.lable.pleaseSelect"/>操作<spring:message code="message.listForm.DeShangPin"/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code="message.HN.alert.type"/>", "error");
    			return;
    		}
    		var list = [];
    		for (var i=0; i<rowIds.length; i++) {
    			rowId = rowIds[i];
				list.push({"drugId":rowId,"projId":'${bidProject.projId}'});
    		}
    		submitDrugTOProj(JSON.stringify(list));
        }
        
        
        
    	function submitDrugTOProj(list){
           	$.ajax({
				type:"POST",
				url:"batchSubmitDrugTOProj.html",
				data:{"drugs":list},
				dataType:"json",
				success:function(returnData){
					if (returnData.success == true) {
						$("#gridlist").jqGrid("clearGridData");
	    				$("#gridlist").jqGrid().trigger("reloadGrid");
	    				$.HN.message.alert("<spring:message code="message.yanZheng.TianJiaYaoPinChengGong"/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code="message.HN.alert.type"/>", "success");
	    			} else {
	    				$.HN.message.alert("<spring:message code="message.yanZheng.TianJiaYaoPinShiBai"/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code="message.HN.alert.type"/>", "error");
	    			}
				}
			});
        	
        }
		
    </script>
</body>
</html>